home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / TextArea.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-30  |  5.8 KB  |  189 lines

  1. package symantec.itools.db.awt;
  2.  
  3. import java.awt.Event;
  4. import java.awt.TextComponent;
  5. import java.io.IOException;
  6. import symantec.itools.db.pro.ProjBinder;
  7. import symantec.itools.db.pro.ProjLink;
  8. import symantec.itools.db.pro.RelationView;
  9. import symantec.itools.db.pro.RelationViewMetaData;
  10. import symjava.sql.SQLException;
  11.  
  12. public class TextArea extends java.awt.TextArea implements ProjLink {
  13.    private ProjBinder m_ProjBinder;
  14.    private boolean m_DynamicUpdate = false;
  15.    private boolean m_DynamicUpdateOverride = true;
  16.    private boolean m_BinderDetermines = true;
  17.    private String m_BinderData = new String();
  18.    private String m_ScreenData = new String();
  19.    private int m_treatBlankAs;
  20.  
  21.    public TextArea() {
  22.    }
  23.  
  24.    public TextArea(int rows, int cols) {
  25.       super(rows, cols);
  26.    }
  27.  
  28.    public TextArea(String text) {
  29.       super(text);
  30.    }
  31.  
  32.    public TextArea(String text, int rows, int cols) {
  33.       super(text, rows, cols);
  34.    }
  35.  
  36.    public void init(ProjBinder binder) {
  37.       this.m_ProjBinder = binder;
  38.       this.setEditable(this.m_ProjBinder);
  39.    }
  40.  
  41.    public void setTreatBlankAs(String blank) {
  42.       if ((new String(blank)).toUpperCase().equals("DEFAULT")) {
  43.          this.m_treatBlankAs = 0;
  44.       } else if ((new String(blank)).toUpperCase().equals("NULL")) {
  45.          this.m_treatBlankAs = 1;
  46.       } else {
  47.          if ((new String(blank)).toUpperCase().equals("EMPTY")) {
  48.             this.m_treatBlankAs = 2;
  49.          }
  50.  
  51.       }
  52.    }
  53.  
  54.    public void setBinding(RelationView relView, String projection) {
  55.       int projectionNumber = 0;
  56.       int columnType = 0;
  57.  
  58.       try {
  59.          RelationViewMetaData rvmd = relView.getMetaData();
  60.          projectionNumber = relView.findProjByName(projection);
  61.          columnType = rvmd.getColumnType(projectionNumber);
  62.          if (columnType == 91 || columnType == 92 || columnType == 93) {
  63.             this.m_DynamicUpdateOverride = false;
  64.          }
  65.  
  66.          relView.bindProj(projectionNumber, this);
  67.       } catch (SQLException Ex) {
  68.          this.raiseException("SQLException from setBinding: " + ((Throwable)Ex).getMessage());
  69.       }
  70.    }
  71.  
  72.    public void setDynamicUpdate(boolean update) {
  73.       this.m_DynamicUpdate = update;
  74.    }
  75.  
  76.    public void notifyDataChange(ProjBinder binder) {
  77.       if (binder != null) {
  78.          this.m_ProjBinder = binder;
  79.  
  80.          try {
  81.             if (binder.getRelationView().getCurrentRecordState() != 105) {
  82.                if (binder.isReadable() && !binder.isNull()) {
  83.                   this.m_BinderData = binder.getStringValue();
  84.                } else {
  85.                   this.m_BinderData = "";
  86.                }
  87.             } else {
  88.                this.m_BinderData = "";
  89.             }
  90.          } catch (SQLException Ex) {
  91.             this.raiseException("SQLException from TextArea.notifyDataChange: " + ((Throwable)Ex).getMessage());
  92.          } catch (IOException Ex) {
  93.             this.raiseException("IOException from TextArea.notifyDataChange: " + ((Throwable)Ex).getMessage());
  94.          }
  95.  
  96.          if (this.m_BinderData == null) {
  97.             this.m_BinderData = new String();
  98.          }
  99.  
  100.          this.m_ScreenData = ((TextComponent)this).getText();
  101.          if (!this.m_BinderData.equals(this.m_ScreenData)) {
  102.             this.m_ScreenData = this.m_BinderData;
  103.             ((TextComponent)this).setText(this.m_ScreenData);
  104.          }
  105.  
  106.          if (this.m_BinderDetermines) {
  107.             this.setEditable(this.m_ProjBinder);
  108.          }
  109.  
  110.       }
  111.    }
  112.  
  113.    public boolean lostFocus(Event evt, Object what) {
  114.       try {
  115.          this.notifySetData(this.m_ProjBinder);
  116.       } catch (SQLException Ex) {
  117.          this.raiseException("SQLException from TextArea.notifySetData: " + ((Throwable)Ex).getMessage());
  118.       }
  119.  
  120.       return super.lostFocus(evt, what);
  121.    }
  122.  
  123.    boolean notifyInputChanged(String input) {
  124.       if (!this.m_ScreenData.equals(input)) {
  125.          this.m_ScreenData = input;
  126.       }
  127.  
  128.       if (!this.m_BinderData.equals(this.m_ScreenData)) {
  129.          this.m_BinderData = this.m_ScreenData;
  130.  
  131.          try {
  132.             if (this.m_ProjBinder != null && this.m_ProjBinder.isWritable()) {
  133.                this.m_ProjBinder.setValueFromString(this.m_ScreenData, 0, this.m_treatBlankAs);
  134.             }
  135.          } catch (SQLException Ex) {
  136.             this.raiseException("SQLException from TextArea.notifyInputChange.setString: " + ((Throwable)Ex).getMessage());
  137.             return false;
  138.          } catch (IOException Ex) {
  139.             this.raiseException("IOException from TextArea.notifyInputChange.setString: " + ((Throwable)Ex).getMessage());
  140.             return false;
  141.          }
  142.       }
  143.  
  144.       return true;
  145.    }
  146.  
  147.    public boolean notifySetData(ProjBinder binder) throws SQLException {
  148.       return this.notifyInputChanged(((TextComponent)this).getText());
  149.    }
  150.  
  151.    public boolean handleEvent(Event evt) {
  152.       if (this.m_DynamicUpdate && this.m_DynamicUpdateOverride) {
  153.          try {
  154.             this.notifySetData(this.m_ProjBinder);
  155.          } catch (SQLException Ex) {
  156.             this.raiseException("SQLException from TextArea.notifySetData: " + ((Throwable)Ex).getMessage());
  157.          }
  158.       }
  159.  
  160.       return super.handleEvent(evt);
  161.    }
  162.  
  163.    void setEditable(ProjBinder binder) {
  164.       boolean isWritable = false;
  165.  
  166.       try {
  167.          if (binder != null) {
  168.             RelationView rv = binder.getRelationView();
  169.             if (rv != null && rv.getCurrentRecordState() != 105) {
  170.                isWritable = binder.isWritable();
  171.             }
  172.          }
  173.       } catch (SQLException Ex) {
  174.          this.raiseException("SQLException from setEditable: " + ((Throwable)Ex).getMessage());
  175.       }
  176.  
  177.       super.setEditable(isWritable);
  178.    }
  179.  
  180.    public void setEditable(boolean value) {
  181.       this.m_BinderDetermines = value;
  182.       super.setEditable(value);
  183.    }
  184.  
  185.    void raiseException(String text) {
  186.       System.out.println(text);
  187.    }
  188. }
  189.